$(function () {
    $("span.ljtip").ljDetail($("#cgwzjhsp_detail_ljtip").val(), {
        position: 'top'
    });

    var id = $("#wzjhglsp_zjjhid").val();
    var type = $("#wzjhglsp_type").val();

    var zgwzjhmxCol = [
        {field: 'wzgg.code', title: '物资编码', align: 'center', width: 100},
        {field: 'wzgg.name', title: '物资名称', align: 'center', width: 100},
        {field: 'ggxh', title: '规格型号', align: 'center', width: 100},
        {field: 'wzgg.dw', title: '单位', align: 'center', width: 100},
        {field: 'cd.z', title: '产地', align: 'center', width: 100},
        {field: 'sbsl', title: '计划数量', width: 100, align: 'right', formatter: function (value) {
            var sl = formatSlForHtml(value, ",");
            return sl;
        }}
    ];

    var tpwzjhmxCol = [
        {field: 'wzgg.code', title: '物资编码', align: 'center', width: 100},
        {field: 'wzgg.name', title: '物资名称', align: 'center', width: 100},
        {field: 'ggxh', title: '规格型号', align: 'center', width: 100},
        {field: 'wzgg.dw', title: '单位', align: 'center', width: 100},
        {field: 'cd.z', title: '产地', align: 'center', width: 100},
//        {field: 'ck', title: '长宽', width: 100},
        {field: 'jzfs.z', title: '记重方式', align: 'center', width: 100},
        {field: 'sbsl', title: '计划数量', width: 100, align: 'right', formatter: function (value) {
            var sl = formatSlForHtml(value, ",");
            return sl;
        }},
        {field: 'hdsl', editor: {type: 'numberbox', options: {min: 0, groupSeparator: ',', precision: 4}}, title: '核定数量',
            formatter: function (value) {
                var sl = formatSlForHtml(value, ",");
                return sl;
            }, align: 'right', width: 100},
        {field: 'bz', title: '备注', align: 'center', width: 100}
    ];

    var col = null;
    if (type == "Tpwzjh")
        col = tpwzjhmxCol;
    if (type == "Zgwzjh")
        col = zgwzjhmxCol;
    $("#wzjhglsp_wzjhmx_grid").edatagrid({
        rownumbers: "true",
        singleSelect: "true",
        fitColumns: true,
        showFooter: true,
        url: $.webPath() + "/jhgl/wzjhgl/wzjhmxList?id=" + id + "&type=" + type,
        columns: [col],
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align','center');
        },
        loadFilter: function (data) {
            $.each(data.rows, function () {
                if (this.hdsl && this.hdsl == 0) {
                    this.hdsl = this.sbsl;
                }
            })
            return data;
        },
        onSelect: function (rowIndex, rowData) {
            //获取每个单元格
            $("#wzjhglsp_wzjhmx_grid").edatagrid('editRow', rowIndex);
            var editors = $("#wzjhglsp_wzjhmx_grid").datagrid('getEditors', rowIndex);
            if (editors.length == 0)
                return;
        }
    });

});

function viewXyspDetail(xyId, xyType) {
    if (xyType != null && xyType == "Cgxy") {
        var type = 1;
    } else if (xyType != null && xyType == "Xsxy") {
        type = 2;
    } else if (xyType != null && xyType == "Sfxy") {
        type = 3;
    }
    $.window({
        title: '详细信息',
        iconCls: 'icon-tip',
        url: $.webPath() + "/jhgl/xygl/xygl_detail?type=" + type + "&xyId=" + xyId,
        width: 1050,
        height: 450
    })
}
